package com.aspire.boc.mms.wmf.service.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.aspire.boc.mms.wmf.dao.wmf.WmfKeyMapper;
import com.aspire.boc.mms.wmf.dao.wmf.WmfOperateLogMapper;
import com.aspire.boc.mms.wmf.model.WmfOperateLog;
import com.aspire.boc.mms.wmf.model.WmfOperateLogExample;
import com.aspire.boc.mms.wmf.service.OperateLogService;
import com.aspire.boc.mms.wmf.util.Page;

@Service
public class OperateLogServiceImpl implements OperateLogService {

	private Log log = LogFactory.getLog(this.getClass());

	@Autowired
	WmfOperateLogMapper operateLogMapper;

	@Transactional
	@Override
	public Integer insertOperateLog(WmfOperateLog operateLog) throws Exception {
		int res = -1;
		try {
			operateLog.setId(wmfKeyMapper.getNextLogID().longValue());
			res = operateLogMapper.insertSelective(operateLog);
		} catch (Exception e) {
			log.error("添加操作日志异常", e);
			throw e;
		}
		return res;
	}

	@Transactional
	@Override
	public List<WmfOperateLog> queryOperateLog(WmfOperateLogExample operateLogExample) {
		List<WmfOperateLog> listWmfOperateLog = null;
		try {
			listWmfOperateLog = operateLogMapper.selectByExample(operateLogExample);
			log.info("获取操作日志列表");
		} catch (Exception e) {
			log.error("获取操作日志异常", e);
		}
		return listWmfOperateLog;
	}
	
	@Override
	public List<WmfOperateLog> queryOperateLogPage(Page page) {
		WmfOperateLogExample wmfOperateLogExample = new WmfOperateLogExample();
		wmfOperateLogExample.setPage(page);
		wmfOperateLogExample.setOrderByClause("TIMESTAMP DESC");
		return wmfOperateLogMapper.selectByExample(wmfOperateLogExample);
	}
	
	@Override
	public long queryOperateLogCount() {
		return wmfOperateLogMapper.countByExample(null);
	}
	
	@Autowired
	private WmfKeyMapper wmfKeyMapper;
	@Autowired
	private WmfOperateLogMapper wmfOperateLogMapper;
}
